/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.envconfig;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;

import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import com.google.inject.jndi.JndiIntegration;

/**
 *
 * @author Pete
 */
public class EnvConfigModule extends AbstractModule {

    @Override
    protected void configure() {
    	bind(DataSource.class).toProvider(JndiIntegration.fromJndi(DataSource.class, "java:comp/env/jdbc/EnvironmentConfiguration"));
        bind(EntityManagerFactory.class).toProvider(PersistenceProvider.class).in(Singleton.class);
    }
    
    @Provides
    protected Context getContext() throws NamingException {
    	return new InitialContext();
    }

}
